package org.dromara.xyyw.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xyyw.domain.bo.XyywCouponAcquireRecordBo;
import org.dromara.xyyw.domain.query.XyywCouponAcquireRecordQuery;
import org.dromara.xyyw.domain.vo.XyywCouponAcquireRecordVo;
import org.dromara.xyyw.service.IXyywCouponAcquireRecordService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 用户领取记录
 *
 * @author yf
 * @date 2024-05-29
 */
@Validated
@RestController
@RequestMapping("/xyyw/couponAcquireRecord")
public class XyywCouponAcquireRecordController extends BaseController {

    @Autowired
    private IXyywCouponAcquireRecordService xyywCouponAcquireRecordService;

    /**
     * 查询用户领取记录列表
     */
    @SaCheckPermission("xyyw:couponAcquireRecord:list")
    @GetMapping("/list")
    public TableDataInfo<XyywCouponAcquireRecordVo> list(XyywCouponAcquireRecordQuery query) {
        return xyywCouponAcquireRecordService.queryPageList(query);
    }

    /**
     * 导出用户领取记录列表
     */
    @SaCheckPermission("xyyw:couponAcquireRecord:export")
    @Log(title = "用户领取记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XyywCouponAcquireRecordQuery query, HttpServletResponse response) {
        List<XyywCouponAcquireRecordVo> list = xyywCouponAcquireRecordService.queryList(query);
        ExcelUtil.exportExcel(list, "用户领取记录", XyywCouponAcquireRecordVo.class, response);
    }

    /**
     * 获取用户领取记录详细信息
     *
     * @param recordId 主键
     */
    @SaCheckPermission(value = {"xyyw:couponAcquireRecord:query", "xyyw:couponAcquireRecord:edit"}, mode = SaMode.OR)
    @GetMapping("/{recordId}")
    public R<XyywCouponAcquireRecordVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer recordId) {
        return R.ok(xyywCouponAcquireRecordService.queryById(recordId));
    }

    /**
     * 新增用户领取记录
     */
    @SaCheckPermission("xyyw:couponAcquireRecord:add")
    @Log(title = "用户领取记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XyywCouponAcquireRecordBo bo) {
        return toAjax(xyywCouponAcquireRecordService.insertByBo(bo));
    }

    /**
     * 修改用户领取记录
     */
    @SaCheckPermission("xyyw:couponAcquireRecord:edit")
    @Log(title = "用户领取记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XyywCouponAcquireRecordBo bo) {
        return toAjax(xyywCouponAcquireRecordService.updateByBo(bo));
    }

    /**
     * 删除用户领取记录
     *
     * @param recordIds 主键串
     */
    @SaCheckPermission("xyyw:couponAcquireRecord:remove")
    @Log(title = "用户领取记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Integer[] recordIds) {
        return toAjax(xyywCouponAcquireRecordService.deleteWithValidByIds(List.of(recordIds)));
    }
}
